class MinStack:
  def __init__(self):
    self.stack = list()
    self.min_element = 2147483647
    self.min_list = list()

  def push(self, x: int) -> None:
    self.stack.append(x)
    if x <= self.min_element:
      self.min_element = x
      self.min_list.append(x)

  def pop(self) -> None:
    popped = self.stack.pop()
    if popped == self.min_element:
      self.min_list.pop()
      if len(self.min_list) == 0:
        self.min_element = 2147483647
      else:
        self.min_element = self.min_list[-1]

  def top(self) -> int:
    return self.stack[-1]

  def min(self) -> int:
    return self.min_element


'''
STATUS: SOLVED
TRIES:  2
TIME:   72 MS
MEMORY: 16.5 MB
'''
if __name__ == "__main__":
  min_stack = MinStack()
  min_stack.push(-2)
  min_stack.push(0)
  min_stack.push(-3)
  print(min_stack.min())
  min_stack.pop()
  print(min_stack.top())
  print(min_stack.min())
